package com.asd.system.service.Impl;

import com.asd.system.entity.Role;
import com.asd.system.mapper.RoleMapper;
import com.asd.system.service.IRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @createtime 2021-09-13 14:20
 * @description
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;


    @Override
    public List<Role> selectUserPage(Page<Role> page) {
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();

        //   queryWrapper  可以为null  不进行条件判断
        //  返回list 调用  selectPage

        IPage<Role> roleIPage = roleMapper.selectPage(page, queryWrapper);

        //getRecords()分页对象记录列表
        List<Role> records = roleIPage.getRecords();

        return records;
    }

    @Override
    public boolean deleteBatchRole(String[] roleids) {
//        //1.删除角色和用户关系
//        sysUserMapper.deleteBathRoleUserRelation(roleIds);
//        //2.删除角色和权限关系
//        sysUserMapper.deleteBathRolePermissionRelation(roleIds);
//        //3.删除角色
//        this.removeByIds(Arrays.asList(roleIds));
        return true;
    }


    @Override
    public boolean deleteRole(String roleid) {
        //1.删除角色和用户关系
        roleMapper.deleteRoleUserRelation(roleid);
//        //2.删除角色和权限关系
//        roleMapper.deleteRolePermissionRelation(roleid);
        //3.删除角色
        this.removeById(roleid);
        return true;
    }


}
